package com.cheng.io.print;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 改变标准输入流的数据源为文件或网络
 */
public class SystemInTest02 {
    public static void main(String[] args) {
        try {
            // 修改数据源为文件
            System.setIn(new FileInputStream("io/resources/log"));
            // 获取标准流
            InputStream in = System.in;

            // 一次读取1kb
            byte[] bytes = new byte[1024];
            // 读取数据
            int readCount = in.read(bytes);
            System.out.println(new String(bytes,0,readCount));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
